<?php

/**
 * This is the model class for table "tbl_item".
 *
 * The followings are the available columns in table 'tbl_item':
 * @property string $id
 * @property integer $amount
 * @property integer $freeze
 * @property string $tbl_item_group_id
 * @property string $tbl_item_template_id
 * @property string $tbl_store_id
 * @property string $tbl_substore_id
 *
 * The followings are the available model relations:
 * @property TblItemGroup $tblItemGroup
 * @property TblItemTemplate $tblItemTemplate
 * @property TblStore $tblStore
 * @property TblSubstore $tblSubstore
 */
class Item extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Item the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_item';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('tbl_item_group_id, tbl_item_template_id, tbl_store_id, tbl_substore_id', 'required'),
			array('amount, freeze', 'numerical', 'integerOnly'=>true),
			array('tbl_item_group_id, tbl_item_template_id, tbl_store_id, tbl_substore_id', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, amount, freeze, tbl_item_group_id, tbl_item_template_id, tbl_store_id, tbl_substore_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tblItemGroup' => array(self::BELONGS_TO, 'TblItemGroup', 'tbl_item_group_id'),
			'tblItemTemplate' => array(self::BELONGS_TO, 'TblItemTemplate', 'tbl_item_template_id'),
			'tblStore' => array(self::BELONGS_TO, 'TblStore', 'tbl_store_id'),
			'tblSubstore' => array(self::BELONGS_TO, 'TblSubstore', 'tbl_substore_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'amount' => 'Amount',
			'freeze' => 'Freeze',
			'tbl_item_group_id' => 'Tbl Item Group',
			'tbl_item_template_id' => 'Tbl Item Template',
			'tbl_store_id' => 'Tbl Store',
			'tbl_substore_id' => 'Tbl Substore',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('amount',$this->amount);
		$criteria->compare('freeze',$this->freeze);
		$criteria->compare('tbl_item_group_id',$this->tbl_item_group_id,true);
		$criteria->compare('tbl_item_template_id',$this->tbl_item_template_id,true);
		$criteria->compare('tbl_store_id',$this->tbl_store_id,true);
		$criteria->compare('tbl_substore_id',$this->tbl_substore_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}